OpenBuildings GenerativeComponents Help

AddFrom

Returns a new list comprising all members of the given list, plus all members of the given source list.

object[] AddFrom(object[] list, object[] sourceList,
	optional bool function(object sourceMember, ...) selector,
...)

If the selector function is given, then only those members of the source list for which the selector function returns true are added.

This function does not change the given list. To add new members directly to the end of a list, call the AddFrom method on that list, itself.

Using AddFrom

AddFrom adds each member from a source list that satisfies the given function, to the end of another list.

How to use it:

a) One line format:

int[] combinedList  = AddFrom(list, sourceList, function(int
number){return number > 4;});

b) Multi-line format

function selectionCriteral(int number)
{
	return number > 4;
}
int[] combinedList  = AddFrom(list, sourceList, selectionCriteral);

Examples using AddFrom

a) Adds all the members of the sourceList to the end of the list.  No function is needed in this case.

int[] list = {1, 2, 3, 4};
int[] sourceList = {3, 4, 5, 6};
int[] resultingList = AddFrom(list, sourceList); //resultingList
= {1, 2, 3, 4, 3, 4, 5, 6}

b) Using a function to determine selection criteria AddFrom adds all the members of the sourceList that fulfil the selection criteria to the end of the list.  In the example all the numbers greater than 4.

int[] list = {1, 2, 3, 4};
int[] sourceList = {3, 4, 5, 6};
function addSelection(int number)
{
	return number > 4;
}
int[] resultingList = AddFrom(list, sourceList, addSelection);
//resultingList = {1, 2, 3, 4, 5, 6}

c) Additional arguments can be given to the function. These are placed after the function. In the following example the variable minimumHeight is passed into the function. The newly created list resulting from the AddFrom function can be assigned to a new variable as in the two previous examples or assigned to one of the original lists so that it overwrites their values. This is shown in the example below.

list = AddFrom(list, sourceList, function(int number, int
min){return number > min;}, minimumHeight);